//app.js
 import myFetch from "./api/fetch.js";
 import api from "./api/api.js"
App({
   checkIsLogin() {
        return wx.getStorageSync('token') != '' && wx.getStorageSync('user_id') != '';
      },
    getUserInfo(e, callback) {
        let App = this;
        if (e.detail.errMsg !== 'getUserInfo:ok') {
          return false;
        }
        wx.showLoading({
          title: "正在登录",
          mask: true
        });
        // 执行微信登录
        wx.login({
          success(res) {
            console.log(res);
    // 向后台发送数据
            myFetch({url:api.login
                ,data: {
                  code:res.code,
                  user_info: e.detail.rawData,
                  encrypted_data: e.detail.encryptedData,
                  iv: e.detail.iv,
                  signature: e.detail.signature,
                  wxapp_id:10001,
                },method:"post"}).then(res=>{
                  console.log(res.data);
                  wx.setStorageSync('token', res.data.data.token);
                  wx.setStorageSync('user_id', res.data.data.user_id);
                    // 执行回调函数
                   callback();
                   wx.hideLoading();
                // console.log(res.data);
            }).catch(error=>{
                console.log(error);
            });     
          }
        });
      },
  globalData: {
    userInfo: null
  },
})